package com.car.web.controller.finance;

import java.io.IOException;
import java.io.PrintWriter;
import java.net.URLEncoder;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.car.dal.dao.goods.*;
import com.car.dal.object.*;
import com.car.util.*;
import com.google.gson.Gson;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import org.apache.log4j.Logger;
import org.json.JSONException;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.car.dal.dao.office.TgOfficeDao;
import com.car.dal.dao.user.UserinfoDao;
import com.car.exception.BaseException;
import com.car.util.JsonExecutor.JsonBiz;
import com.car.util.WebExecutor.Biz;
import com.car.web.controller.base.BaseController;
import com.car.web.controller.base.BaseVo;
import com.car.web.controller.index.LoginVo;

@Controller
@RequestMapping("/goods")
public class GoodsController extends BaseController {
    private static final Logger logger = Logger
            .getLogger(GoodsController.class);
    @Resource
    private TgOfficeDao tgOfficeDao;
    @Resource
    private TgGoodsDao goodsDao;
    @Resource
    private TgGoodsNameDao goodsNameDao;
    @Resource
    private TgGoodsAccountDao tgGoodsAccountDao;
    @Resource
    private TgGoodsKeyDao tgGoodKeyDao;
    @Resource
    private TgPurchaseManageDao tgPurchaseManageDao;
    @Resource
    private GoodsMnusDao goodsMnusDao;
    @Resource
    private GoodsNewDao goodsNewDao;
    @Resource
    private GoodsShDao goodsShDao;
    @Resource
	private GoodsServiceDao goodsServiceDao;
    @Resource
    private UserinfoDao userinfoDao;
    //物品列表
    //旧版，可以按照中心查询
    @RequestMapping(value = "/goodsList")
    public ModelAndView posList(ModelMap modelMap, final BaseVo vo, final HttpServletRequest request)
            throws Exception {
        modelMap = WebExecutor.execute(logger, vo, new Biz() {
            public Result process() {
                Result result = new ResultSupport(true);
                String goodsId = request.getParameter("good_name_id");
                String center_name = request.getParameter("center_name");
                TgGoods goods = new TgGoods();
                TgGoodsKey tgGoodKey = null;
                if (goodsId == null || "".equals(goodsId) || Long.valueOf(goodsId) == 1) {
                    goods.setGood_name_id(1l);
                    if (center_name != null && !center_name.equals("全部")) {
                    	goods.setCenter_name(center_name);
                    }
                    goods.setField("center_name,model,code,purpose,state,msg");
                } else if (Long.valueOf(goodsId) == 2) {
                    goods.setGood_name_id(2l);
                    goods.setField("item_name,use_period,postage,residual_length,msg");    //404电话
                } else if (Long.valueOf(goodsId) == 3) {
                    goods.setGood_name_id(3l);
                    if (center_name != null && !center_name.equals("全部")) {
                    	goods.setCenter_name(center_name);
                    }
                    goods.setField("center_name,msg,renew_time,postage,supplier,broadband_type,broadband_type2");    //宽带
                } else if (Long.valueOf(goodsId) == 4) {
                    goods.setGood_name_id(4l);
                    goods.setField("item_name,number,msg,unit_price,purchasing_link");//办公家具
                } else if (Long.valueOf(goodsId) == 5) {
                    goods.setGood_name_id(5l);
                    goods.setField("item_name,model,code,purchasing_link");        //流量卡
                } else if (Long.valueOf(goodsId) == 6) {
                    goods.setGood_name_id(6l);
                    goods.setField("item_name,number,unit_price,msg");    //办公相关
                } else if (Long.valueOf(goodsId) == 7) {
                    goods.setGood_name_id(7l);
                    goods.setField("item_name,number,unit_price,msg");    //伯温文具+玩具
                } else if (Long.valueOf(goodsId) == 8) {
                    goods.setGood_name_id(8l);
                    if (center_name != null && !center_name.equals("全部")) {
                    	goods.setCenter_name(center_name);
                    }
                    goods.setField("item_name,number,company,center_name,msg");    //学院路寄送物品
                } else if (Long.valueOf(goodsId) == 9) {
                    goods.setGood_name_id(9l);
                    goods.setField("item_name,number,unit_price,purchasing_link");    //训练用品
                } else if (Long.valueOf(goodsId) == 10) {
                    goods.setGood_name_id(10l);
                    goods.setField("item_name,number,purchasing_link");        //书籍
                } else if (Long.valueOf(goodsId) == 11) {
                    goods.setGood_name_id(11l);
                    goods.setField("item_name,msg,number,purchasing_link");    //灯具
                } else if (Long.valueOf(goodsId) == 12) {
                    goods.setGood_name_id(12l);
                    goods.setField("item_name,number");//消耗品
                } else if (Long.valueOf(goodsId) == 13) {    //钥匙
                    tgGoodKey = new TgGoodsKey();
                    if (center_name != null && !center_name.equals("全部")) {
                        tgGoodKey.setCenter_name(center_name);
                    }
                } else if (Long.valueOf(goodsId) == 14) {
                    goods.setGood_name_id(14l);
                    if (center_name != null && !center_name.equals("全部")) {
                    	goods.setCenter_name(center_name);
                    }
                    goods.setField("center_name,model,code,phone,responsible_tea");//手机资费情况
                } else if (Long.valueOf(goodsId) == 15) {
                    goods.setGood_name_id(15l);
                    if (center_name != null && !center_name.equals("全部")) {
                    	goods.setCenter_name(center_name);
                    }
                    goods.setField("center_name,number,state");//手机资费情况
                }
                Integer currPage = 1;
                if (vo.getCurrPage() != null && !"".equals(vo.getCurrPage())) {
                    currPage = vo.getCurrPage();
                }
                Integer total;
                Page page;
                if (goodsId != null && !"".equals(goodsId) && Long.valueOf(goodsId) == 13) {
                    total = tgGoodKeyDao.getGoodsKeyCountInfo(tgGoodKey);
                    page = PageUtil.createPage(8, currPage, total);
                    List<TgGoodsKey> list = tgGoodKeyDao.getGoodsKeyInfo(tgGoodKey, page);
                    result.setDefaultModel("list", list);
                    result.setDefaultModel("good_name_id", 13);
                    result.setDefaultModel("center_name", center_name);
                } else {
                    total = goodsDao.getGoodsCountByType(goods);
                    page = PageUtil.createPage(8, currPage, total);
                    List<TgGoods> list = goodsDao.getGoodsByType(goods, page);
                    result.setDefaultModel("list", list);
                    result.setDefaultModel("center_name", center_name);
                    result.setDefaultModel("good_name_id", list.get(0).getGood_name_id());
                }
                TgOffice office = new TgOffice();
                List<TgOffice> offList = tgOfficeDao.getOfficeName(office);
                TgGoodsAccount tgGoodsAccount = new TgGoodsAccount();
                tgGoodsAccount.setApply_status(4);
                tgGoodsAccount.setApplied(1);
                Integer total2 = tgGoodsAccountDao.getGoodsAccountCountInfo(tgGoodsAccount);
                TgGoodsAccount tgGoodsAccount2 = new TgGoodsAccount();
                tgGoodsAccount2.setApply_status(4);
                tgGoodsAccount2.setApplied(2);//仓库申请
                Integer total3 = tgGoodsAccountDao.getGoodsAccountCountInfo(tgGoodsAccount2);
                result.setDefaultModel("offList", offList);
                result.setDefaultModel("page", page);
                result.setDefaultModel("total2", total2);
                result.setDefaultModel("total3", total3);
                return result;
            }
        });
        return new ModelAndView("system/finance/goods/goodslist", modelMap);
    }

    //进入添加库存页
  //新版，新的物品分类，添加
    @RequestMapping(value = "/addGoods")
    public ModelAndView add_method(ModelMap modelMap, final LoginVo loginVo, final HttpServletRequest request)
            throws Exception {
        modelMap = WebExecutor.execute(logger, loginVo, new Biz() {
            public Result process() {
                Result result = new ResultSupport(true);
                String id = request.getParameter("id");
                if (id != null && !id.equals("")) {
                    GoodsNew goods = goodsNewDao.findById(GoodsNew.class, Long.valueOf(id));
                    if(goods!=null){
                		GoodsNew goodsNew=new GoodsNew();
                    	goodsNew.setGoods_child_id(goods.getGoods_child_id());
                    	List<GoodsNew> goodsNewList=goodsNewDao.findByExample(goodsNew);
                    	for(GoodsNew goodsNew2:goodsNewList) {
                    		GoodsMnus gmnus = goodsMnusDao.findById(GoodsMnus.class, goodsNew2.getGood_muns_id());
                    		GoodsMnus gmnus2 = goodsMnusDao.findById(GoodsMnus.class, goodsNew2.getGood_pard_id());
                    		goodsNew2.setGoods_name(gmnus.getName());
                    		goodsNew2.setGood_parint_name(gmnus2.getName());
                    	}
                    	String goods_child_id=JSONObject.fromObject(goodsNewList.get(0)).getString("goods_child_id");
                    	String good_pard_id=JSONObject.fromObject(goodsNewList.get(0)).getString("good_pard_id");
						String msg=JSONObject.fromObject(goodsNewList.get(0)).getString("msg");
						String img_url=JSONObject.fromObject(goodsNewList.get(0)).getString("img_url");
						String region=JSONObject.fromObject(goodsNewList.get(0)).getString("region");
						String type=JSONObject.fromObject(goodsNewList.get(0)).getString("type");
						String apply_status=JSONObject.fromObject(goodsNewList.get(0)).getString("apply_status");
						String supplier=JSONObject.fromObject(goodsNewList.get(0)).getString("supplier");
						result.setDefaultModel("goods_child_id", goods_child_id);
						result.setDefaultModel("good_pard_id", good_pard_id);
						result.setDefaultModel("msg", msg);
						result.setDefaultModel("img_url", img_url);
						result.setDefaultModel("region", region);
						result.setDefaultModel("type", type);
						result.setDefaultModel("apply_status", apply_status);
						result.setDefaultModel("supplier", supplier);
						result.setDefaultModel("goodsNewList", goodsNewList);
                    }
                }
                TgOffice office = new TgOffice();
                List<TgOffice> offList = tgOfficeDao.getOfficeName(office);

                GoodsMnus gm = new GoodsMnus();
                gm.setParint_id(0);
                List<GoodsMnus> list = goodsMnusDao.getGoodsmnus(gm);
                
                result.setDefaultModel("offList", offList);
                result.setDefaultModel("list", list);
                return result;
            }
        });
        return new ModelAndView("system/finance/goods/addGoods", modelMap);
    }

    /**
     * 通过id和子id获取物品申请信息
     * @param modelMap
     * @param vo
     * @param request
     * @return
     * @throws Exception
     */
    
    @RequestMapping(value = "/getGoodsNewsById")
    public ModelAndView getGoodsNewsById(ModelMap modelMap, final BaseVo vo, final HttpServletRequest request)
    		throws Exception {
    	modelMap = JsonExecutor.execute(logger, vo, new JsonBiz() {
    		public Result process() {
    			Result result = new ResultSupport(true);
    			String goodsId = request.getParameter("goodsId");
    			String goods_child_id = request.getParameter("goods_child_id");
    			GoodsNew goodn = new GoodsNew();
    			TgUser user = UserUtil.getUserFromCookies();
    			if(null!=goodsId&&!goodsId.equals("")) {
    				goodn.setId(Long.valueOf(goodsId));
    				goodn.setGoods_child_id(goods_child_id);
    				List<GoodsNew> goodsNewsList= goodsNewDao.findByExample(goodn);
    				
    				if(null!=goodsNewsList&&goodsNewsList.size()>0) {
    					result.setDefaultModel("goodsNews", goodsNewsList.get(0));
    				}
    			}
    			return result;
    		}
    	});
    	return new ModelAndView("", modelMap);
    }
    /**
     * 根据子id获取物品申请信息
     * @param modelMap
     * @param vo
     * @param request
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/getGoodsNewsListById")
    public ModelAndView getGoodsNewsListById(ModelMap modelMap, final BaseVo vo, final HttpServletRequest request)
    		throws Exception {
    	modelMap = JsonExecutor.execute(logger, vo, new JsonBiz() {
    		public Result process() {
    			Result result = new ResultSupport(true);
    			String goods_child_id = request.getParameter("goods_child_id");
    			GoodsNew goodn = new GoodsNew();
				goodn.setGoods_child_id(goods_child_id);
				List<GoodsNew> goodsNewsList= goodsNewDao.findByExample(goodn);
				
				if(null!=goodsNewsList&&goodsNewsList.size()>0) {
					result.setDefaultModel("goodsNewsList", goodsNewsList);
				}
    			return result;
    		}
    	});
    	return new ModelAndView("", modelMap);
    }
    /*我的申请列表
     * 审核未审核都会出现
     * 
     * */
    
    @RequestMapping(value = "/myGoodsList")
    public ModelAndView myGoodsList(ModelMap modelMap, final BaseVo vo, final HttpServletRequest request)
            throws Exception {
        modelMap = WebExecutor.execute(logger, vo, new Biz() {
            public Result process() {
                Result result = new ResultSupport(true);
                String center = request.getParameter("center");
                String itemName = request.getParameter("itemName");
                String auditStatus = request.getParameter("auditStatus");
                String startTime = request.getParameter("startTime");
                String endTime = request.getParameter("endTime");
                GoodsNew goodn = new GoodsNew();
                TgUser user = UserUtil.getUserFromCookies();
                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//                goodn.setUsername(user.getUsername());
                try {
					if(user.getNickname().equals("刘岚")||user.getNickname().equals("檀文娟")) {
						 goodn.setPurchaser("");
					}else {
						goodn.setPurchaser(user.getNickname());
					}
					if (auditStatus != null && !"".equals(auditStatus)) {
						goodn.setApply_status(Integer.valueOf(auditStatus));
					}
					if (center != null && !"".equals(center)) {
						goodn.setCenter_name(center);
					}
					if (itemName != null && !"".equals(itemName)) {
						goodn.setItem_name(itemName);
					}
					if (startTime != null && !"".equals(startTime)&& !"undefined".equals(startTime)) {
						goodn.setStartTime(sdf.parse(startTime+" 00:00:00"));
					}
					if (endTime != null && !"".equals(endTime)&&!"undefined".equals(endTime)) {
						goodn.setEndTime(sdf.parse(endTime+" 23:59:59"));
					}
					List<GoodsNew> goods = goodsNewDao.getGoodsNewList(goodn);
					if(goods!=null && !"".equals(goods)){
						for(GoodsNew gw : goods){
							GoodsMnus gmnus = goodsMnusDao.findById(GoodsMnus.class, gw.getGood_muns_id());
							gw.setGoods_name(gmnus.getName());
						}
						for(int i=0;i<goods.size();i++) {
							String goods_child_id=goods.get(i).getGoods_child_id();
							if(null!=goods_child_id&&!goods_child_id.equals("")) {
								for(int j=i+1;j<goods.size();j++) {
									if(goods_child_id.equals(goods.get(j).getGoods_child_id())) {
										String typeName="";
										if(goods.get(j).getType()==1) {
											typeName="固定资产";
										}else if(goods.get(j).getType()==2) {
											typeName="消耗品";
										}
										
										goods.get(i).setGoods_childs((null!=goods.get(i).getGoods_childs()&&!goods.get(i).getGoods_childs().equals("")?goods.get(i).getGoods_childs():"")+goods.get(j).getGoods_name()+"&nbsp;&nbsp;"+goods.get(j).getItem_name()+"&nbsp;&nbsp;"
												+(goods.get(j).getNumber()==null?"":goods.get(j).getNumber())+"&nbsp;&nbsp;"+typeName+"&nbsp;&nbsp;"+(goods.get(j).getPurchasing_num()==null?"":goods.get(j).getPurchasing_num())+"&nbsp;&nbsp;"+(goods.get(j).getPurchasing_link()==null?"":goods.get(j).getPurchasing_link())+"&nbsp;<br>");
										goods.remove(j);
										j=i;
									}
								}
							}
						}
					}
					Integer currPage = 1;
					if (vo.getCurrPage() != null && !"".equals(vo.getCurrPage())) {
						currPage = vo.getCurrPage();
					}
					Integer total = goods.size();
					Page page = PageUtil.createPage(8, currPage, total);
					if((currPage-1)*8+8>total){//说明这一页超出了总的页数
						goods=goods.subList((currPage-1)*8, total);
					}else{
						goods=goods.subList((currPage-1)*8, (currPage-1)*8+8);
					}
					GoodsMnus gm = new GoodsMnus();
					gm.setParint_id(0);
					List<GoodsMnus> Mnuslist = goodsMnusDao.getGoodsmnus(gm);
					TgOffice office = new TgOffice();
					List<TgOffice> offList = tgOfficeDao.getOfficeName(office);
					result.setDefaultModel("offList", offList);
					result.setDefaultModel("Mnuslist", Mnuslist);
					result.setDefaultModel("list", goods);
					result.setDefaultModel("page", page);
					result.setDefaultModel("user", user);
					result.setDefaultModel("auditStatus", auditStatus);
					result.setDefaultModel("center", center);
					result.setDefaultModel("itemName", itemName);
					result.setDefaultModel("startTime", startTime);
					result.setDefaultModel("endTime", endTime);
					result.setDefaultModel("purchasePerson", goods.size()>0?goods.get(0).getPurchasePerson():"");
					result.setDefaultModel("good_muns_id", goods != null && goods.size() > 0 ? goods.get(0).getGood_muns_id() : "");
				} catch (Exception e) {
					e.printStackTrace();
				} 
                return result;
            }
        });
        return new ModelAndView("system/finance/goods/my_goods_list", modelMap);
    }

    /**
     * 更新物品申请信息
     * @param modelMap
     * @param vo
     * @param request
     * @return
     * @throws BaseException
     */
    @RequestMapping(value = "/update_goods_go")
    public ModelAndView update_goods_go(ModelMap modelMap, final BaseVo vo, final HttpServletRequest request)
    		throws BaseException {
    	modelMap = JsonExecutor.execute(logger, vo, new JsonBiz() {
    		public Result process() {
    			Result result = new ResultSupport(true);
    			String goodid = request.getParameter("goodid");
    			String goods_child_id = request.getParameter("goods_child_id");
    			String number = request.getParameter("number");
    			String supplier = request.getParameter("supplier");
    			String unitPrice = request.getParameter("unitPrice");
    			String totalCalculation = request.getParameter("totalCalculation");
    			String goods_price_total = request.getParameter("goods_price_total");
    			String purchasing_num = request.getParameter("purchasing_num");
    			String purchasing_link = request.getParameter("purchasing_link");
    			TgUser user = UserUtil.getUserFromCookies();
    			Date date = new Date();
    			GoodsNew goodn = new GoodsNew();
    			
    			if (goods_child_id != null && !"".equals(goods_child_id)) {
    				goodn.setGoods_child_id(goods_child_id);
    			}
    			if (number != null && !"".equals(number)) {
    				goodn.setNumber(Integer.valueOf(number));
    			}
    			if (supplier != null && !"".equals(supplier)) {
    				goodn.setSupplier(supplier);
    			}
    			if (unitPrice != null && !"".equals(unitPrice)) {
    				goodn.setUnit_price(Double.valueOf(unitPrice));
    			}
    			if (totalCalculation != null && !"".equals(totalCalculation)) {
    				goodn.setTotal_calculation(Double.valueOf(totalCalculation));
    			}
    			if (purchasing_num != null && !"".equals(purchasing_num)) {
    				goodn.setPurchasing_num(purchasing_num);
    			}
    			if (purchasing_link != null && !"".equals(purchasing_link)) {
    				goodn.setPurchasing_link(purchasing_link);
    			}
    			goodn.setApplied(1);//表示是申请
    			goodn.setCreate_time(date);
    			goodn.setPurchasing_num(purchasing_num);
    			if(goodid!=null && !"".equals(goodid)){
    				GoodsNew good = goodsNewDao.findById(GoodsNew.class, Long.valueOf(goodid));
    				if(good!=null){
    					goodn.setId(Long.valueOf(goodid));
    					goodsNewDao.update(goodn);
    					
    					goodn=new GoodsNew();
    					if (goods_price_total != null && !"".equals(goods_price_total)) {
    						goodn.setGoods_child_id(goods_child_id);
    						List<GoodsNew> goodsNewList=goodsNewDao.findByExample(goodn);
    						for(GoodsNew goods:goodsNewList) {
    							goodn.setId(goods.getId());
    							goodn.setGoods_price_total(Double.valueOf(goods_price_total));
    							goodsNewDao.update(goodn);
    						}
    					}
    					result.setDefaultModel("msg", "1");
    				}
    			}
    			return result;
    		}
    	});
    	return new ModelAndView("", modelMap);
    }
    //添加库存
    //添加物品申请，不同物品有几个分类，可以修改
    
    @RequestMapping(value = "/add_goods_go")
    public ModelAndView add_method_go(ModelMap modelMap, final BaseVo vo, final HttpServletRequest request)
            throws BaseException {
        modelMap = JsonExecutor.execute(logger, vo, new JsonBiz() {
            public Result process() {
                Result result = new ResultSupport(true);
                String goodid = request.getParameter("goodid");
                String goods_child_id = request.getParameter("goods_child_id");
                String img_url = request.getParameter("img_url");
                String msg = request.getParameter("msg");
                TgUser user = UserUtil.getUserFromCookies();
                
                if(goods_child_id!=null && !"".equals(goods_child_id)){
                	GoodsNew good = new GoodsNew();
                	good.setGoods_child_id(goods_child_id);
                	List<GoodsNew> goodsNewsList= goodsNewDao.getGoodsNewList(good);
                	if(goodsNewsList!=null&&goodsNewsList.size()>0){
                		for(GoodsNew goodsNews:goodsNewsList) {
                			GoodsNew goodn = new GoodsNew();
                			
                			goodn.setId(goodsNews.getId());
                			goodn.setImg_url(img_url);
                			goodn.setMsg(msg);
                			goodsNewDao.update(goodn);
                		}
                		result.setDefaultModel("msg", "1");
                	}
                }
                return result;
            }
        });
        return new ModelAndView("", modelMap);
    }

    //列表2级菜单栏
    @RequestMapping(value = "/goodsMnus")
    public ModelAndView goodsMnus(ModelMap modelMap, final BaseVo vo,
       final HttpServletRequest request, HttpServletResponse response)
            throws BaseException {
        modelMap = JsonExecutor.execute(logger, vo, new JsonBiz() {
            public Result process() {
                Result result = new ResultSupport(true);
                String id = request.getParameter("good_mnus");
                GoodsMnus gm = new GoodsMnus();
            	List<GoodsMnus> list = goodsMnusDao.getGoodsmnus(gm);
            	result.setDefaultModel("list",list);
                return result;
            }
        });
        return new ModelAndView("", modelMap);
    }
    
    
    /*我的审核列表
     * Apply_status=1未审核，过来审核
     * */
    @RequestMapping(value = "/ShGoods")
    public ModelAndView ShGoods(ModelMap modelMap, final BaseVo vo, final HttpServletRequest request)
            throws Exception {
        modelMap = WebExecutor.execute(logger, vo, new Biz() {
            public Result process() {
                Result result = new ResultSupport(true);
                String center = request.getParameter("center");
                String auditStatus = request.getParameter("auditStatus");
                GoodsNew goodn = new GoodsNew();
                TgUser user = UserUtil.getUserFromCookies();
                goodn.setUsername(user.getUsername());
                if (auditStatus != null && !"".equals(auditStatus)) {
                	goodn.setApply_status(Integer.valueOf(auditStatus));
                }else{
                	auditStatus = "1";
                	goodn.setApply_status(1);
                }
                if (center != null && !"".equals(center)) {
                	goodn.setCenter_name(center);
                }
                Integer currPage = 1;
                if (vo.getCurrPage() != null && !"".equals(vo.getCurrPage())) {
                    currPage = vo.getCurrPage();
                }
                Integer total = goodsNewDao.getGoodsNewCount(goodn);
                Page page = PageUtil.createPage(8, currPage, total);
                List<GoodsNew> list = goodsNewDao.getGoodsnew(goodn, page);
                if(list!=null){
                	for(GoodsNew gw : list){
                		GoodsMnus gmnus = goodsMnusDao.findById(GoodsMnus.class, gw.getGood_muns_id());
                		gw.setGoods_name(gmnus.getName());
                	}
                }
                
                GoodsMnus gm = new GoodsMnus();
                gm.setParint_id(0);
                List<GoodsMnus> Mnuslist = goodsMnusDao.getGoodsmnus(gm);
                TgOffice office = new TgOffice();
                List<TgOffice> offList = tgOfficeDao.getOfficeName(office);
                result.setDefaultModel("offList", offList);
                result.setDefaultModel("Mnuslist", Mnuslist);
                result.setDefaultModel("list", list);
                result.setDefaultModel("page", page);
                result.setDefaultModel("center", center);
                result.setDefaultModel("auditStatus", auditStatus);
                result.setDefaultModel("good_muns_id", list != null && list.size() > 0 ? list.get(0).getGood_muns_id() : "");
                return result;
            }
        });
        return new ModelAndView("system/finance/goods/goods_audit_list", modelMap);
    }
    
    //进入物品采购审核页面
    @RequestMapping(value = "/auditGoods")
    public ModelAndView auditGoods(ModelMap modelMap, final LoginVo loginVo, final HttpServletRequest request)
            throws Exception {
        modelMap = WebExecutor.execute(logger, loginVo, new Biz() {
            public Result process() {
                Result result = new ResultSupport(true);
                String id = request.getParameter("id");
                if (id != null && !id.equals("")) {
                    GoodsNew goods = goodsNewDao.findById(GoodsNew.class, Long.valueOf(id));
                    if(goods!=null){
                		GoodsMnus gmnus = goodsMnusDao.findById(GoodsMnus.class, goods.getGood_muns_id());
                		GoodsMnus gmnus2 = goodsMnusDao.findById(GoodsMnus.class, goods.getGood_pard_id());
                		goods.setGoods_name(gmnus.getName());
                		goods.setGood_parint_name(gmnus2.getName());
                    }
                    result.setDefaultModel("goods", goods);
                }

                return result;
            }
        });
        return new ModelAndView("system/finance/goods/auditGoods", modelMap);
    }
    //进入物品采购评价页面
    @RequestMapping(value = "/toSeePurchaseGoods")
    public ModelAndView toSeePurchaseGoods(ModelMap modelMap, final LoginVo loginVo, final HttpServletRequest request)
    		throws Exception {
    	modelMap = JsonExecutor.execute(logger, loginVo, new JsonBiz() {
    		public Result process() {
    			Result result = new ResultSupport(true);
    			String id=request.getParameter("id");
				
				if(null!=id&&!id.equals("")) {
//					String url = "http://127.0.0.1:8080/web/oa/toQueryPurchase.json?id="+id;
					String url = "http://a.jingsiedu.com/oa/toQueryPurchase.json?id="+id;
					String obj = HttpUtil.doGet(url, "", "utf-8", true);
					JSONArray goodsList=JSONObject.fromObject(obj).getJSONArray("goodsNewList");
					JSONObject goodsNewObj = JSONObject.fromObject(goodsList.get(0));
					GoodsNew goods=new GoodsNew();
					if(goodsNewObj.getString("purchasePerson")!=null&&!goodsNewObj.getString("purchasePerson").equals("")&&!goodsNewObj.getString("purchasePerson").equals("null")){
						goods.setPurchasePerson(Integer.parseInt(goodsNewObj.getString("purchasePerson")));
					}
					if(goodsNewObj.getString("purchaseGoods")!=null&&!goodsNewObj.getString("purchaseGoods").equals("")&&!goodsNewObj.getString("purchaseGoods").equals("null")){
						goods.setPurchaseGoods(Integer.parseInt(goodsNewObj.getString("purchaseGoods")));
					}
					goods.setPurchaseMessage(goodsNewObj.getString("purchaseMessage"));

					result.setDefaultModel("goods",goods);
				}
    			return result;
    		}
    	});
    	return new ModelAndView("", modelMap);
    }
    //下载物品申请信息
    @RequestMapping(value = "/toDownloadGoodsInfomationList")
    public ModelAndView toDownloadGoodsInfomationList(ModelMap modelMap, final LoginVo loginVo, final HttpServletRequest request)
    		throws Exception {
    	modelMap = JsonExecutor.execute(logger, loginVo, new JsonBiz() {
    		public Result process() {
    			Result result = new ResultSupport(true);
    			String center=request.getParameter("center");
    			String itemName=request.getParameter("itemName");
    			String audit_status=request.getParameter("audit_status");
    			String startTime=request.getParameter("startTime");
    			String endTime=request.getParameter("endTime");
    			
    			GoodsNew goods = new GoodsNew();
    			SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    			try {
					if(null!=center&&!center.equals("")) {
						goods.setCenter(center);
					}
					if(null!=itemName&&!itemName.equals("")) {
						goods.setItem_name(itemName);
					}
					if(null!=audit_status&&!audit_status.equals("")) {
						goods.setApply_status(Integer.valueOf(audit_status));
					}
					if(null!=startTime&&!startTime.equals("")) {
						goods.setStartTime(sdf.parse(startTime+" 00:00:00"));
					}
					if(null!=endTime&&!endTime.equals("")) {
						goods.setEndTime(sdf.parse(endTime+" 23:59:59"));
					}
					
					List<GoodsNew> goodsNewList= goodsNewDao.getGoodsNewList(goods);
					if(null!=goodsNewList&&goodsNewList.size()>0) {
						for(GoodsNew goodsNew:goodsNewList) {
							GoodsMnus gmnus = goodsMnusDao.findById(GoodsMnus.class, goodsNew.getGood_muns_id());
							goodsNew.setGoods_name(gmnus.getName());
						}
						String name=WriterExcel.downloadGoodsInfomationList(goodsNewList,startTime,endTime);
						result.setDefaultModel("name", name);
					}
				} catch (Exception e) {
					e.printStackTrace();
				} 
    			return result;
    		}
    	});
    	return new ModelAndView("", modelMap);
    }
    
    @RequestMapping(value = "/ajaxAudit")//物品审核，采购审核一样使用这个方法
    public ModelAndView ajaxAudit(ModelMap modelMap, final BaseVo vo, final HttpServletRequest request)
            throws BaseException {
        modelMap = JsonExecutor.execute(logger, vo, new JsonBiz() {
            public Result process() {
                Result result = new ResultSupport(true);
                
                String id = request.getParameter("id");
                String auditStatus = request.getParameter("auditStatus");//1审核失败，2审核成功
                String all_words = request.getParameter("all_words");//图片地址
                String msg = request.getParameter("msg");
                TgUser user = UserUtil.getUserFromCookies();
                if (msg == null || "".equals(msg)) {
                    msg = "无";
                }
                if (id != null && !"".equals(id)) {
                	GoodsNew good = goodsNewDao.findById(GoodsNew.class, Long.valueOf(id));
                	if(good!=null){
                		GoodsNew goodsNew=new GoodsNew();
                		GoodsSh gsh = new GoodsSh();
                		goodsNew.setGoods_child_id(good.getGoods_child_id());
                		List<GoodsNew> goodsNewList=goodsNewDao.findByExample(goodsNew);
                		for(GoodsNew goodsNew2:goodsNewList) {
                			goodsNew2.setApply_status(Integer.valueOf(auditStatus));
                			goodsNew2.setImg_url(all_words);
                			goodsNewDao.update(goodsNew2);
                			if(auditStatus=="2"||"2".equals(auditStatus)){
                				gsh.setSh_name(user.getUsername());
                				gsh.setGood_id(Integer.valueOf(id));
                				if(msg!= null && !"".equals(msg)){
                					gsh.setSh_msg(msg);
                				}
                				gsh.setCreate_time(new Date());
                				gsh.setCg_msg("无");
                				gsh.setRk_name("无");
                				gsh.setCenter_name(good.getCenter_name());
                				goodsShDao.insert(gsh);
                				
                				result.setDefaultModel("msg", "1");
                			}else if(auditStatus=="1"||"1".equals(auditStatus)){
                				gsh.setGood_id(Integer.valueOf(id));
                				List<GoodsSh> shl = goodsShDao.getGoodsSh(gsh);
                				if(shl!=null &&shl.size()>0){
                					GoodsSh goodsh = shl.get(0);
                					if(msg!= null && !"".equals(msg)){
                						goodsh.setCg_msg(msg);
                					}
                					goodsShDao.update(goodsh);
                					result.setDefaultModel("msg", "1");
                				}
                			}
                		}
                	}else{
                		result.setDefaultModel("msg", "0");
                	}
                }
                return result;
            }
        });
        return new ModelAndView("", modelMap);
    }
    
    
    /*我的采购审核列表
     * 
     * Apply_status=3
     * 已经采购，申请入库
     * */
    @RequestMapping(value = "/CgShGoods")
    public ModelAndView CgShGoods(ModelMap modelMap, final BaseVo vo, final HttpServletRequest request)
            throws Exception {
        modelMap = WebExecutor.execute(logger, vo, new Biz() {
            public Result process() {
                Result result = new ResultSupport(true);
                String goodsId = request.getParameter("pratin");
                String auditStatus = request.getParameter("audit_status");
                String center = request.getParameter("center");
                GoodsNew goodn = new GoodsNew();
                TgUser user = UserUtil.getUserFromCookies();
                goodn.setUsername(user.getUsername());
                if (auditStatus != null && !"".equals(auditStatus)) {
                	goodn.setApply_status(Integer.valueOf(auditStatus));
                }else{
                	goodn.setApply_status(Integer.valueOf(2));
                }
                if(goodsId !=null && !"".equals(goodsId)){
                	
                	goodn.setGood_muns_id(Long.valueOf(goodsId));
                }
                if (center != null && !"".equals(center)) {
                	goodn.setCenter_name(center);
                }
                
                Integer currPage = 1;
                if (vo.getCurrPage() != null && !"".equals(vo.getCurrPage())) {
                    currPage = vo.getCurrPage();
                }
                Integer total = goodsNewDao.getGoodsNewCount(goodn);
                Page page = PageUtil.createPage(8, currPage, total);
                List<GoodsNew> list = goodsNewDao.getGoodsnew(goodn, page);
                if(list!=null){
                	for(GoodsNew gw : list){
                		GoodsMnus gmnus = goodsMnusDao.findById(GoodsMnus.class, gw.getGood_muns_id());
                		gw.setGoods_name(gmnus.getName());
                	}
                }
                
                GoodsMnus gm = new GoodsMnus();
                gm.setParint_id(0);
                List<GoodsMnus> Mnuslist = goodsMnusDao.getGoodsmnus(gm);
                TgOffice office = new TgOffice();
                List<TgOffice> offList = tgOfficeDao.getOfficeName(office);
                result.setDefaultModel("offList", offList);
                result.setDefaultModel("Mnuslist", Mnuslist);
                result.setDefaultModel("list", list);
                result.setDefaultModel("center", center);
                result.setDefaultModel("page", page);
                result.setDefaultModel("auditStatus", auditStatus);
                result.setDefaultModel("good_muns_id", list != null && list.size() > 0 ? list.get(0).getGood_muns_id() : "");
                return result;
            }
        });
        return new ModelAndView("system/finance/goods/procurement_audit_list", modelMap);
    }
    
    //进入
    @RequestMapping(value = "/procurementauditGoods")
    public ModelAndView procurementauditGoods(ModelMap modelMap, final LoginVo loginVo, final HttpServletRequest request)
            throws Exception {
        modelMap = WebExecutor.execute(logger, loginVo, new Biz() {
            public Result process() {
                Result result = new ResultSupport(true);
                String id = request.getParameter("id");
                if (id != null && !id.equals("")) {
                    GoodsNew goods = goodsNewDao.findById(GoodsNew.class, Long.valueOf(id));
                    if(goods!=null){
                		GoodsMnus gmnus = goodsMnusDao.findById(GoodsMnus.class, goods.getGood_muns_id());
                		GoodsMnus gmnus2 = goodsMnusDao.findById(GoodsMnus.class, goods.getGood_pard_id());
                		goods.setGoods_name(gmnus.getName());
                		goods.setGood_parint_name(gmnus2.getName());
                    }
                    result.setDefaultModel("goods", goods);
                }

                return result;
            }
        });
        return new ModelAndView("system/finance/goods/procurement_audit_goods", modelMap);
    }
   /*
    * 库存信息列表
    * 采购审核通过，才可以显示
    * /    
    */
    @RequestMapping(value = "/Goods")
    public ModelAndView Goods(ModelMap modelMap, final BaseVo vo, final HttpServletRequest request)
            throws Exception {
        modelMap = WebExecutor.execute(logger, vo, new Biz() {
            public Result process() {
                Result result = new ResultSupport(true);
                String goodsId = request.getParameter("goodsId");
                String center = request.getParameter("center");
                GoodsNew goodn = new GoodsNew();
                TgUser user = UserUtil.getUserFromCookies();
                goodn.setUsername(user.getUsername());
                goodn.setApply_status(Integer.valueOf(6));
                if(goodsId !=null && !"".equals(goodsId)){
                	
                	goodn.setGood_muns_id(Long.valueOf(goodsId));
                }
                if (center != null && !"".equals(center)) {
                	goodn.setCenter_name(center);
                }
                
                Integer currPage = 1;
                if (vo.getCurrPage() != null && !"".equals(vo.getCurrPage())) {
                    currPage = vo.getCurrPage();
                }
                Integer total = goodsNewDao.getGoodsNewCount(goodn);
                Page page = PageUtil.createPage(8, currPage, total);
                List<GoodsNew> list = goodsNewDao.getGoodsnew(goodn, page);
                if(list!=null){
                	for(GoodsNew gw : list){
                		GoodsMnus gmnus = goodsMnusDao.findById(GoodsMnus.class, gw.getGood_muns_id());
                		gw.setGoods_name(gmnus.getName());
                	}
                }
                
                GoodsMnus gm = new GoodsMnus();
                gm.setParint_id(0);
                List<GoodsMnus> Mnuslist = goodsMnusDao.getGoodsmnus(gm);
                
                
                
                TgOffice office = new TgOffice();
                List<TgOffice> offList = tgOfficeDao.getOfficeName(office);
                
                GoodsNew goodsnew = new GoodsNew();
                goodsnew.setApply_status(4);
                goodsnew.setApplied(1);
                Integer total2 = goodsNewDao.getGoodsNewCount(goodsnew);
                GoodsNew goodsnew2 = new GoodsNew();
                goodsnew2.setApply_status(4);
                goodsnew2.setApplied(2);//仓库申请
                Integer total3 = goodsNewDao.getGoodsNewCount(goodsnew2);
                result.setDefaultModel("total2", total2);
                result.setDefaultModel("total3", total3);
                result.setDefaultModel("offList", offList);
                result.setDefaultModel("Mnuslist", Mnuslist);
                result.setDefaultModel("list", list);
                result.setDefaultModel("page", page);
                result.setDefaultModel("center", center);
                result.setDefaultModel("good_pard_id", list != null && list.size() > 0 ? list.get(0).getGood_pard_id() : "");
                return result;
            }
        });
        return new ModelAndView("system/finance/goods/goods_list", modelMap);
    }
    
    /**
     * 进入到入库页面
     */


    @RequestMapping(value = "/goodsStorage")
    public ModelAndView goodsStorage(ModelMap modelMap, final LoginVo loginVo,
                                     final HttpServletRequest request)
            throws Exception {
        modelMap = WebExecutor.execute(logger, loginVo, new Biz() {
            public Result process() {
                Result result = new ResultSupport(true);
                String flag = request.getParameter("flag");
                GoodsNew goods = new GoodsNew();
                if (flag.equals("1")) {
                	goods.setApply_status(4);
                	goods.setApplied(1);
                } else if (flag.equals("2")) {
                	goods.setApply_status(4);
                	goods.setApplied(2);
                }
                Integer total = goodsNewDao.getGoodsNewCount(goods);
                Page page = PageUtil.createPage(total, 1, total);
                List<GoodsNew> list = goodsNewDao.getGoodsnew(goods, page);
                if(list!=null){
                	for(GoodsNew gw : list){
                		GoodsMnus gmnus = goodsMnusDao.findById(GoodsMnus.class, gw.getGood_muns_id());
                		GoodsMnus gmnus2 = goodsMnusDao.findById(GoodsMnus.class, gw.getGood_pard_id());
                		gw.setGoods_name(gmnus.getName());
                		gw.setGood_parint_name(gmnus2.getName());
                	}
                }
                result.setDefaultModel("total", total);
                result.setDefaultModel("list", list);
                result.setDefaultModel("flag", flag);
                result.setDefaultModel("goods", list != null && list.size() > 0 ? list.get(0) : "");
                return result;
            }
        });
        return new ModelAndView("system/finance/goods/goods_storage", modelMap);
    }
    @RequestMapping(value = "/ajaxSelectGoods")
    public void ajaxSelectGoods(HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        String id = request.getParameter("id");
        GoodsNew goods = goodsNewDao.findById(GoodsNew.class, Long.valueOf(id));
		GoodsMnus gmnus = goodsMnusDao.findById(GoodsMnus.class, goods.getGood_muns_id());
		GoodsMnus gmnus2 = goodsMnusDao.findById(GoodsMnus.class, goods.getGood_pard_id());
		goods.setGoods_name(gmnus.getName());
		goods.setGood_parint_name(gmnus2.getName());

        response.setCharacterEncoding("UTF-8");
        PrintWriter writer = response.getWriter();
        Gson gson = new Gson();
        writer.print(gson.toJson(goods));
    }
    

    @RequestMapping(value = "/saveStorage")//物品审核，采购审核一样使用这个方法
    public ModelAndView saveStorage(ModelMap modelMap, final BaseVo vo, final HttpServletRequest request)
            throws BaseException {
        modelMap = JsonExecutor.execute(logger, vo, new JsonBiz() {
            public Result process() {
                Result result = new ResultSupport(true);
                
                String id = request.getParameter("goodId");
		        String flag = request.getParameter("flag");
		        String purpose = request.getParameter("purpose");
		        GoodsNew goods = goodsNewDao.findById(GoodsNew.class, Long.valueOf(id));
		        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		        TgUser user = UserUtil.getUserFromCookies();
		        if (flag.equals("1")) {
		        	
		        	GoodsSh gsh = new GoodsSh();
		        	gsh.setGood_id(Integer.valueOf(id));
		        	List<GoodsSh> shl = goodsShDao.getGoodsSh(gsh);
		        	if(shl!=null &&shl.size()>0){
		        		goods.setApply_status(6);
			        	goods.setPurpose(purpose);
			        	goodsNewDao.update(goods);
		        		GoodsSh goodsh = shl.get(0);
		        		goodsh.setRk_name(user.getUsername());
			        	goodsShDao.update(goodsh);
			        	result.setDefaultModel("msg", "1");
		        	}else{
		        		result.setDefaultModel("msg", "0");
		        	}
		        }
//		        else if (flag.equals("2")) {
//		        	goods.setApply_status(7);
//		        	goods.setPurpose(purpose);
//		        	goodsNewDao.update(goods);
//		        	GoodsSh gsh = new GoodsSh();
//		        	gsh.setRk_name(user.getUsername());
//		        	goodsShDao.update(gsh);
//		        	result.setDefaultModel("msg", "1");
//		        }
                return result;
            }
        });
        return new ModelAndView("system/finance/goods/goods_list", modelMap);
    }
    

    //进入
    @RequestMapping(value = "/xqGoods")
    public ModelAndView xqGoods(ModelMap modelMap, final LoginVo loginVo, final HttpServletRequest request)
            throws Exception {
        modelMap = WebExecutor.execute(logger, loginVo, new Biz() {
            public Result process() {
                Result result = new ResultSupport(true);
                String id = request.getParameter("id");
                String flag = request.getParameter("flag");
                if (id != null && !id.equals("")) {
                	GoodsNew goods = goodsNewDao.findById(GoodsNew.class, Long.valueOf(id));
	                if(goods!=null){
	            		GoodsNew goodsNew=new GoodsNew();
	                	goodsNew.setGoods_child_id(goods.getGoods_child_id());
	                	List<GoodsNew> goodsNewList=goodsNewDao.findByExample(goodsNew);
	                	for(GoodsNew goodsNew2:goodsNewList) {
	                		GoodsMnus gmnus = goodsMnusDao.findById(GoodsMnus.class, goodsNew2.getGood_muns_id());
	                		GoodsMnus gmnus2 = goodsMnusDao.findById(GoodsMnus.class, goodsNew2.getGood_pard_id());
	                		goodsNew2.setGoods_name(gmnus.getName());
	                		goodsNew2.setGood_parint_name(gmnus2.getName());
	                	}
	                	String goods_child_id=JSONObject.fromObject(goodsNewList.get(0)).getString("goods_child_id");
	                	String good_pard_id=JSONObject.fromObject(goodsNewList.get(0)).getString("good_pard_id");
						String msg=JSONObject.fromObject(goodsNewList.get(0)).getString("msg");
						String img_url=JSONObject.fromObject(goodsNewList.get(0)).getString("img_url");
						String region=JSONObject.fromObject(goodsNewList.get(0)).getString("region");
						String type=JSONObject.fromObject(goodsNewList.get(0)).getString("type");
						String apply_status=JSONObject.fromObject(goodsNewList.get(0)).getString("apply_status");
						String supplier=JSONObject.fromObject(goodsNewList.get(0)).getString("supplier");
						result.setDefaultModel("goods_child_id", goods_child_id);
						result.setDefaultModel("good_pard_id", good_pard_id);
						result.setDefaultModel("msg", msg);
						result.setDefaultModel("img_url", img_url);
						result.setDefaultModel("region", region);
						result.setDefaultModel("type", type);
						result.setDefaultModel("apply_status", apply_status);
						result.setDefaultModel("supplier", supplier);
						result.setDefaultModel("goodsNewList", goodsNewList);
						result.setDefaultModel("goods", goodsNewList.get(0));
						
		               	 TgOffice office = new TgOffice();
		                 List<TgOffice> offList = tgOfficeDao.getOfficeName(office);
		
		                 GoodsMnus gm = new GoodsMnus();
		                 gm.setParint_id(0);
		                 List<GoodsMnus> list = goodsMnusDao.getGoodsmnus(gm);
		                 
		                 result.setDefaultModel("offList", offList);
		                 result.setDefaultModel("list", list);
	
	                }
                    result.setDefaultModel("flag", flag);
                }

                return result;
            }
        });
        return new ModelAndView("system/finance/goods/xq_goods", modelMap);
    }
    /**
     * 物品维修列表
     * @param modelMap
     * @param vo
     * @param request
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/goodsServiceList")
    public ModelAndView goodsServiceList(ModelMap modelMap, final BaseVo vo, final HttpServletRequest request)
    		throws Exception {
    	modelMap = WebExecutor.execute(logger, vo, new Biz() {
    		public Result process() {
    			Result result = new ResultSupport(true);
    			String id = request.getParameter("id");
    			String goods_state = request.getParameter("goods_state");
    			String center = request.getParameter("center");
    			String startTime = request.getParameter("startTime");
    			String endTime = request.getParameter("endTime");
    			String goodsServiceType = request.getParameter("goodsServiceType");
    			String serviceType = request.getParameter("serviceType");
    			SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    			TgUser user=UserUtil.getUserFromCookies();
    			
    			GoodsService goodsService=new GoodsService();
				try {
					if(user.getDepartments().equals("行政教务部")) {
						goodsService.setAuditname(user.getNickname());
						if(null!=goods_state&&!goods_state.equals("")) {
							goodsService.setGoods_state(Integer.valueOf(goods_state));
						}
						String username=encode(user.getNickname());
						String url = "http://yueqiao.org/web/teaweb/getTeacherAreaByTeaName.json?username="+username;
//						String url = "http://127.0.0.1:8081/web/teaweb/getTeacherAreaByTeaName.json?username="+username;
						String obj = HttpUtil.doGet(url, "", "utf-8", true);
						JSONObject jsonObject = JSONObject.fromObject(obj);
						
						JSONArray teachersList = JSONObject.fromObject(jsonObject).getJSONArray("teachersList");
						List<TgXzteacher> teacherslist=new ArrayList<TgXzteacher>();
						if(teachersList!=null && teachersList.size()>0){
							for(int i=0;i<teachersList.size();i++) {
								TgXzteacher teacher=new TgXzteacher();
								Gson gson = new Gson();
								String s = teachersList.get(i).toString();
								teacher = gson.fromJson(s, TgXzteacher.class);
								teacher.setName(teacher.getFz_center());
								teacherslist.add(teacher);
							}
							result.setDefaultModel("teacherslist", teacherslist);
						}
					}else {
						if(null!=goods_state&&!goods_state.equals("")) {
							goodsService.setGoods_state(Integer.valueOf(goods_state));
						}else {
							goodsService.setGoods_state2("2");
						}
						
						TgOffice office = new TgOffice();
		                List<TgOffice> teacherslist = tgOfficeDao.getOfficeName(office);
		                
		                result.setDefaultModel("teacherslist", teacherslist);
					}
					
					if(null!=center&&!center.equals("")) {
						goodsService.setCenter(center);
					}
					if(null!=id&&!id.equals("")) {
						goodsService.setId(Long.valueOf(id));
					}
					if(null!=goodsServiceType&&!goodsServiceType.equals("")) {
						goodsService.setGoodsServiceType(Integer.valueOf(goodsServiceType));
					}
					if(null!=serviceType&&!serviceType.equals("")) {
						goodsService.setServiceType(Integer.valueOf(serviceType));
					}
					if(null!=startTime&&!startTime.equals("")) {
						goodsService.setSdate(sdf.parse(startTime+" 00:00:00"));
					}
					if(null!=endTime&&!endTime.equals("")) {
						goodsService.setEdate(sdf.parse(endTime+" 23:59:59"));
					}
					Integer currPage = 1;
	                if (vo.getCurrPage() != null && !"".equals(vo.getCurrPage())) {
	                    currPage = vo.getCurrPage();
	                }
					List<GoodsService> goodsServicesList= goodsServiceDao.getGoodsServiceListByInfo(goodsService);
					
					Integer total = goodsServicesList.size();
					Page page = PageUtil.createPage(8, currPage, total);
					if((currPage-1)*8+8>total){//说明这一页超出了总的页数
						goodsServicesList=goodsServicesList.subList((currPage-1)*8, total);
					}else{
						goodsServicesList=goodsServicesList.subList((currPage-1)*8, (currPage-1)*8+8);
					}
					for(GoodsService service:goodsServicesList) {
						String[] serviceDetails={"地面","墙面","墙面广告","LOGO","漏水","停电","窗帘","门窗","座椅","储物柜","茶几","前台桌","铜牌","沙发"
								,"训练道具","其他物品","电灯","空调","饮水机","其他电器","堵塞","马桶破损","洗手台破损","POS机","分屏器","显示屏","电脑","投影仪"
								,"打印机","录音笔","电话机","手机","考勤机","其他"};
						service.setServiceDetailName(serviceDetails[Integer.valueOf(service.getServiceDetail())-1]);
					}
					result.setDefaultModel("goodsServicesList", goodsServicesList);
					result.setDefaultModel("page", page);
					result.setDefaultModel("center", center);
					result.setDefaultModel("goodsServiceType", goodsServiceType);
					result.setDefaultModel("serviceType", serviceType);
					result.setDefaultModel("startTime", startTime);
					result.setDefaultModel("endTime", endTime);
					result.setDefaultModel("goods_state", goods_state);
				} catch (Exception e) {
					e.printStackTrace();
				} 
    			
    			return result;
    		}
    	});
    	return new ModelAndView("system/finance/goods/goodsServiceList", modelMap);
    }
    /**
     * 下载物品维修信息
     * @param modelMap
     * @param vo
     * @param request
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/toDownloadGoodsServiceList")
    public ModelAndView toDownloadGoodsServiceList(ModelMap modelMap, final BaseVo vo, final HttpServletRequest request)
    		throws Exception {
    	modelMap = JsonExecutor.execute(logger, vo, new JsonBiz() {
    		public Result process() {
    			Result result = new ResultSupport(true);
    			String id = request.getParameter("id");
    			String goods_state = request.getParameter("goods_state");
    			String center = request.getParameter("center");
    			String startTime = request.getParameter("startTime");
    			String endTime = request.getParameter("endTime");
    			String goodsServiceType = request.getParameter("goodsServiceType");
    			String serviceType = request.getParameter("serviceType");
    			SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    			TgUser user=UserUtil.getUserFromCookies();
    			
    			GoodsService goodsService=new GoodsService();
    			try {
    				if(user.getDepartments().equals("行政教务部")) {
    					goodsService.setAuditname(user.getNickname());
    					if(null!=goods_state&&!goods_state.equals("")) {
    						goodsService.setGoods_state(Integer.valueOf(goods_state));
    					}
    					String username=encode(user.getNickname());
						String url = "http://yueqiao.org/web/teaweb/getTeacherAreaByTeaName.json?username="+username;
//    					String url = "http://127.0.0.1:8081/web/teaweb/getTeacherAreaByTeaName.json?username="+username;
    					String obj = HttpUtil.doGet(url, "", "utf-8", true);
    					JSONObject jsonObject = JSONObject.fromObject(obj);
    					
    					JSONArray teachersList = JSONObject.fromObject(jsonObject).getJSONArray("teachersList");
    					List<TgXzteacher> teacherslist=new ArrayList<TgXzteacher>();
    					if(teachersList!=null && teachersList.size()>0){
    						for(int i=0;i<teachersList.size();i++) {
    							TgXzteacher teacher=new TgXzteacher();
    							Gson gson = new Gson();
    							String s = teachersList.get(i).toString();
    							teacher = gson.fromJson(s, TgXzteacher.class);
    							teacher.setName(teacher.getFz_center());
    							teacherslist.add(teacher);
    						}
    						result.setDefaultModel("teacherslist", teacherslist);
    					}
    				}
    				
    				if(null!=center&&!center.equals("")) {
    					goodsService.setCenter(center);
    				}
    				if(null!=id&&!id.equals("")) {
    					goodsService.setId(Long.valueOf(id));
    				}
    				if(null!=goodsServiceType&&!goodsServiceType.equals("")) {
    					goodsService.setGoodsServiceType(Integer.valueOf(goodsServiceType));
    				}
    				if(null!=serviceType&&!serviceType.equals("")) {
    					goodsService.setServiceType(Integer.valueOf(serviceType));
    				}
    				if(null!=startTime&&!startTime.equals("")) {
    					goodsService.setSdate(sdf.parse(startTime+" 00:00:00"));
    				}
    				if(null!=endTime&&!endTime.equals("")) {
    					goodsService.setEdate(sdf.parse(endTime+" 23:59:59"));
    				}
    				List<GoodsService> goodsServicesList= goodsServiceDao.getGoodsServiceListByInfo(goodsService);
    				
    				for(GoodsService service:goodsServicesList) {
    					String[] serviceDetails={"地面","墙面","墙面广告","LOGO","漏水","停电","窗帘","门窗","座椅","储物柜","茶几","前台桌","铜牌","沙发"
    							,"训练道具","其他物品","电灯","空调","饮水机","其他电器","堵塞","马桶破损","洗手台破损","POS机","分屏器","显示屏","电脑","投影仪"
    							,"打印机","录音笔","电话机","手机","考勤机","其他"};
    					service.setServiceDetailName(serviceDetails[Integer.valueOf(service.getServiceDetail())-1]);
    				}
    				result.setDefaultModel("goodsServicesList", goodsServicesList);
    			} catch (Exception e) {
    				e.printStackTrace();
    			} 
    			
    			return result;
    		}
    	});
    	return new ModelAndView("system/finance/goods/goodsServiceList", modelMap);
    }
    /**
     * 行政老师审核物品维修首页
     * @param modelMap
     * @param vo
     * @param request
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/toGoodsServiceCheck")
    public ModelAndView toGoodsServiceCheck(ModelMap modelMap, final BaseVo vo, final HttpServletRequest request)
    		throws Exception {
    	modelMap = WebExecutor.execute(logger, vo, new Biz() {
    		public Result process() {
    			Result result = new ResultSupport(true);
    			String id = request.getParameter("id");
    			String flag = request.getParameter("flag");
    			TgUser user=UserUtil.getUserFromCookies();
    			
				if(null!=id&&!id.equals("")) {
					GoodsService goodsService= goodsServiceDao.findById(GoodsService.class, Long.valueOf(id));
					result.setDefaultModel("goodsService", goodsService);
					TgOffice office=new TgOffice();
					office.setName(goodsService.getCenter());
					List<TgOffice> tgOfficeList = tgOfficeDao.findByExample(office);
					result.setDefaultModel("tgOfficeList", tgOfficeList);
					
//					String url = "http://127.0.0.1:8080/web/oa/getGoodsServiceDetail.json?good_mnus="+goodsService.getServiceType();
					String url = "http://a.jingsiedu.com/oa/getGoodsServiceDetail.json?good_mnus="+goodsService.getServiceType();
					String obj = HttpUtil.doGet(url, "", "utf-8", true);
					JSONObject jsonObject = JSONObject.fromObject(obj);
					JSONArray goodsServicesList= jsonObject.getJSONArray("serviceDetails");
					List<GoodsServiceDetail> servicesDetailList=new ArrayList<GoodsServiceDetail>();
					if(goodsServicesList!=null && goodsServicesList.size()>0){
						for(int i=0;i<goodsServicesList.size();i++){
							GoodsServiceDetail goodsServiceDetail=new GoodsServiceDetail();
							Gson gson = new Gson();
							String s = goodsServicesList.get(i).toString();
							goodsServiceDetail = gson.fromJson(s, GoodsServiceDetail.class);
							
							if(goodsServiceDetail.getServiceDetail()==Long.valueOf(goodsService.getServiceDetail())) {
								goodsService.setServiceDetailName(goodsServiceDetail.getServiceDetailName());
								break;
							}
						}
						result.setDefaultModel("servicesDetailList", servicesDetailList);
					}
					TgUserinfo userInfo=new TgUserinfo();
					userInfo.setJob("项目监理");//项目监理
					List<TgUserinfo> userinfos=userinfoDao.getUserInfoByUserInfo(userInfo);
					
					TgUserinfo userInfo2=new TgUserinfo();
					userInfo2.setJob("维修专员");//维修专员
					List<TgUserinfo> userinfos2=userinfoDao.getUserInfoByUserInfo(userInfo2);
					if(null!=userinfos2&&userinfos2.size()>0) {
						for(TgUserinfo userinfo:userinfos2) {
							userinfos.add(userinfo);
						}
					}
					result.setDefaultModel("userinfos", userinfos);
				}
				
				result.setDefaultModel("flag", flag);
    			return result;
    		}
    	});
    	return new ModelAndView("system/finance/goods/toGoodsService", modelMap);
    }
    /**
     * 物品维修行政老师和维修老师修改状态
     * @param modelMap
     * @param vo
     * @param request
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/updateGoodsServiceState")
    public ModelAndView updateGoodsServiceState(ModelMap modelMap, final BaseVo vo, final HttpServletRequest request)
    		throws Exception {
    	modelMap = JsonExecutor.execute(logger, vo, new JsonBiz() {
    		public Result process() {
    			Result result = new ResultSupport(true);
    			String id = request.getParameter("id");
    			String goods_State = request.getParameter("goods_State");
    			String goods_State2 = request.getParameter("goods_State2");
    			String servicename = request.getParameter("servicename");
    			GoodsService goodsService=new GoodsService();
    			if(null!=goods_State&&!goods_State.equals("")) {
    				goodsService.setGoods_state(Integer.valueOf(goods_State));
    			}
    			if(null!=goods_State2&&!goods_State2.equals("")) {
    				goodsService.setGoods_state(Integer.valueOf(goods_State2));
    			}
    			goodsService.setServicename(servicename);
    			if(goods_State2.equals("4")) {
    				goodsService.setService_time(new Date());
    			}
    			if(null!=id&&!id.equals("")) {
    				GoodsService goodsServices= goodsServiceDao.findById(GoodsService.class, Long.valueOf(id));
    				if(null!=goodsServices) {
    					goodsService.setId(Long.valueOf(id));
    					goodsServiceDao.update(goodsService);
    					result.setDefaultModel("msg", 1);
    				}else {
    					result.setDefaultModel("msg", 2);
    				}
    			}else {
    				result.setDefaultModel("msg", 1);
    			}
    			
    			return result;
    		}
    	});
    	return new ModelAndView("", modelMap);
    }
    /**
     * 查看物品维修评价信息
     * @param modelMap
     * @param vo
     * @param request
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/toSeeGoodsService")
    public ModelAndView toSeeGoodsService(ModelMap modelMap, final BaseVo vo, final HttpServletRequest request)
    		throws Exception {
    	modelMap = JsonExecutor.execute(logger, vo, new JsonBiz() {
    		public Result process() {
    			Result result = new ResultSupport(true);
    			String id = request.getParameter("id");
    			if(null!=id&&!id.equals("")) {
    				GoodsService goodsService= goodsServiceDao.findById(GoodsService.class, Long.valueOf(id));
    				if(null!=goodsService) {
    					result.setDefaultModel("goodsService", goodsService);
    				}
    			}
    			return result;
    		}
    	});
    	return new ModelAndView("", modelMap);
    }
    /**
	 * 接口链接转码
	 * @param str
	 * @return
	 */
	public String encode(String str) {
		try {
			if(str!=null&& !"".equals(str) && !"null".equals(str)){
				str = URLEncoder.encode(str, "utf-8");
			}else {
				str = "";
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return str;
	}
}
